import {createRouter, createWebHistory} from 'vue-router'
import IndexView from '@/views/IndexView.vue'
import NotFoundView from '@/views/NotFoundView.vue'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/',
            component: IndexView,
            meta: {title: '首页'},
            children: [
                {
                    path: '',
                    name: 'Home',
                    component: () => import('@/views/HomeView.vue'),
                    meta: {
                        title: '主页',
                        breadcrumb: [
                            {title: '首页', path: '/'},
                        ]
                    }
                },
                {
                    path: '/articles/',
                    name: 'ArticleList',
                    component: () => import('@/views/ArticleListView.vue'),
                    meta: {
                        title: '文章列表',
                        breadcrumb: [
                            {title: '首页', path: '/'},
                            {title: '文章列表', path: '/articles/'}
                        ]
                    }
                },
                {
                    path: '/articles/:id/:slug/',
                    name: 'ArticleDetail',
                    component: () => import('@/views/ArticleDetailView.vue'),
                    meta: {
                        title: '文章详情',
                        breadcrumb: [
                            {title: '首页', path: '/'},
                            {title: '文章列表', path: '/articles/'},
                            {title: '文章详情', path: '/articles/:id/:slug/'}
                        ]
                    }
                },
                {
                    path: '/categories/:id/:slug/',
                    name: 'CategoryDetail',
                    component: () => import('@/views/CategoryDetailView.vue'),
                    meta: {
                        title: '分类详情',
                        breadcrumb: [
                            {title: '首页', path: '/'},
                            {title: '分类详情', path: '/categories/:id/:slug/'}
                        ]
                    }
                },
                {
                    path: '/tags/:id/:slug/',
                    name: 'TagDetail',
                    component: () => import('@/views/TagDetailView.vue'),
                    meta: {
                        title: '标签详情',
                        breadcrumb: [
                            {title: '首页', path: '/'},
                            {title: '标签详情', path: '/tags/:id/:slug/'}
                        ]
                    }
                },
                {
                    path: '/music',
                    name: 'Music',
                    component: () => import('@/views/MusicView.vue'),
                    meta: {
                        title: '标签详情',
                        breadcrumb: [
                            {title: '首页', path: '/'},
                            {title: '音乐', path: '/music/'}
                        ]
                    }
                },

            ]
        },
        {
            path: '/login',
            name: 'Login',
            component: () => import('@/views/LoginView.vue'),
            meta: {title: '登录'}
        },
        {
            path: '/register',
            name: 'Register',
            component: () => import('@/views/RegisterView.vue'),
            meta: {title: '注册'}
        },
        {
            path: '/user',
            name: 'UserCenter',
            component: () => import('@/views/UserCenterView.vue'),
            meta: {title: '用户中心'}
        },

        {
            path: '/:pathMatch(.*)*',
            name: 'not-found',
            component: NotFoundView,
            meta: {title: '404 - 页面未找到'}
        }
    ],
})
// 路由守卫
router.beforeEach((to, from, next) => {
    NProgress.start()
    next()
})

router.afterEach(() => {
    NProgress.done()
})


export default router


